using UnityEngine;
using System.Collections;

using AforgeFramework;
using System.Threading;

public class NeuralCode : MonoBehaviour
{

    #region Atributos
    private TestClass _neural;
    private Thread _thread;
    public bool Done { private set; get; }
    public int Level { private set; get; }
    #endregion 

    #region Start
    void Start ()
    {
        DontDestroyOnLoad(this);
        
        _thread = new Thread(TrainNetWork);
        _thread.Start();
	}
    #endregion 

    #region Atributos
    public void TrainNetWork()
    {
        //Instanciando Neural
        _neural = new TestClass();
        
        //Treiando a rede
        _neural.TrainNetwork();

        //Sinaliza que ja terminou o treinamento...
        Done = true;
    }

    private float _time;

    /// <summary>
    /// Recebe o tempo que o player  e retorna o nivel que os monstros devem surgir
    /// </summary>
    public void RecognizeNeural(float time)
    {
        Done = false;

        _time = time;

        _thread = new Thread( Recognize);
        _thread.Start();
    }   

    private void Recognize()
    {
        
        double[] input = new double[1];

        input = new double[1]; input[0] = _time;

        Level = (int) _neural.Recognize(input);

        Done = true;
    }
    #endregion 
}
